package com.intcast;

import java.util.Random;
import java.util.Scanner;

/*
双色球案例
*/
public class Demo09 {
    public static void main(String[] args) {
        int[] userBalls = userBalls();
        System.out.println(printBalls(userBalls));
        int[] systemBalls = systemBalls();
        System.out.println(printBalls(systemBalls));
        int resout = star(userBalls, systemBalls);
        System.out.println("中奖" + resout);
    }

    //开始下注
    public static int star(int[] userBalls, int[] systemBalls) {
        int redcount = 0;
        int bluecount = 0;
        for (int i = 0; i < userBalls.length - 1; i++) {
            for (int j = 0; j < systemBalls.length - 1; j++) {
                if (userBalls[i] == systemBalls[j]) {
                    redcount++;
                    break;
                }
            }
        }
        if (userBalls[userBalls.length - 1] == systemBalls[systemBalls.length - 1]) {
            bluecount++;
        }
        if (redcount + bluecount == 7) {
            return 10000000;
        } else if (redcount == 6) {
            return 5000000;
        } else if (redcount + bluecount == 6) {
            return 3000;
        } else if (redcount + bluecount == 5) {
            return 200;
        } else if (redcount + bluecount == 4) {
            return 10;
        } else if (bluecount == 1) {
            return 5;
        } else {
            return 0;
        }
    }


    public static int[] userBalls() {
        Scanner sc = new Scanner(System.in);
        int[] userBalls = new int[7];
        for (int i = 0; i < 6; i++) {

            String printBalls = printBalls(userBalls);
            System.out.println("请输入第" + (i + 1) + "个红球范围[1~33]，现在的球号为：" + printBalls);
            int number = sc.nextInt();
            userBalls[i] = number;
        }
        System.out.println("请输入一个篮球范围[1~16]，前六个红球为：" + printBalls(userBalls));
        int blueBalls = sc.nextInt();
        userBalls[userBalls.length - 1] = blueBalls;
        return userBalls;
    }

    //生成系统随机七个数
    public static int[] systemBalls() {
        int[] systemArr = new int[7];
        Random r = new Random();
        for (int i = 0; i < 6; i++) {
            int systemballs = r.nextInt(33) + 1;
            int count = 0;
            for (int j = 0; j < systemArr.length; j++) {
                if (systemArr[j] == systemballs) {
                    count++;
                    break;
                }
            }
            if (count == 0) {
                systemArr[i] = systemballs;
            } else {
                i--;
            }
        }
        int systemBlue = r.nextInt(17) + 1;
        systemArr[systemArr.length - 1] = systemBlue;
        return systemArr;
    }

    public static String printBalls(int[] userBalls) {
        String strBalls = "[";
        for (int i = 0; i < userBalls.length; i++) {
            if (i == userBalls.length - 1) {
                strBalls += userBalls[i];
            } else {
                strBalls += userBalls[i] + ",";
            }
        }
        strBalls += "]";
        return strBalls;
    }
}
